from twisted.internet import reactor, defer
from mediadart.utils import default_start_mqueue
from mediadart.mqueue.mqserver import startMQ, MQServer


class Pippo(Exception):
    pass

class Calculator(MQServer):
    def mq_prod(self, a, b):
        print ('starting %s' % a)
        return a
        if b > 100:
            d = defer.Deferred()
            reactor.callLater(min(a, 10), d.callback, a)
            return d
        elif b==100:
            raise Pippo('invalid operation')
        else:
            return a*b
#        if a==4 or b == 4:
#            raise Pippo('non so moltiplicare per quattro')
#        else:
#            return a*b


if __name__=='__main__':
    #startMQ(Calculator, 'localhost', 5672, 'guest', 'guest')
    default_start_mqueue(Calculator)
    reactor.run()

